var app = getApp(), u = app.require("utils/util.js"), a = app.require("utils/api.js"), o = app.require("utils/onfire.js"), h = app.require("utils/http.js"), n = app.require("utils/enums");
// pages/mine/evaluate/evaluate.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tabsNames: [
            { id: 0, name: '待评价',type:'un_comment' },
            { id: 1, name: '已评价', type:'comment' }
        ],
        orderlist:[],
        pageindex:1,
        uid:'',
        currectType:'un_comment',
        grouplistbottom:0,
        emtyTxt: '暂无评价信息'
    },
  onLoad: function (el){
      this.data.uid = wx.getStorageSync('userInfo')['uid'];
    this.tabsinit(this.data.currectType);
      console.log('aaaa');
    },
    tabsinit:function(typename){
        var type = "";
        let url='';
        switch (typename) {
            case 'un_comment':
                type = 'un_comment';
            url = a.orderListUrl;
                break;
            case 'comment':
                type = 'comment';
            url = a.userComment;
                break;
            default:
                type = "un_comment";
            url = a.orderListUrl;
                break;
        }
        var t = this;
        var data = {
            store_id: a.storeId,
            uid: t.data.uid,
            type: type,
            page: t.data.pageIndex
      };
        if (t.data.grouplistbottom === 0) {
          h.postReq(url, data, function (res) {
                if (res.code == 0) {
                    if(res.data.next_page === false){
                        t.setData({
                            grouplistbottom:1,
                        });
                    }
                  switch (typename) {
                    case 'un_comment':
                      t.setData({
                        orderlist: t.data.orderlist.concat(res.data.order_list),
                        pageIndex: t.data.pageIndex + 1
                      });
                      break;
                    case 'comment':
                      t.setData({
                        orderlist: t.data.orderlist.concat(res.data.comment_list),
                        pageIndex: t.data.pageIndex + 1
                      });
                      break;
                  }
                   
                }
            });
        }
    },
    // tab切换
    switchTab: function (e) {
        var index = e.currentTarget.dataset.index;
        this.setData({
            currectType:e.currentTarget.dataset.type,
            pageindex:1,
            grouplistbottom:0,
            orderlist:[]
        });
      this.tabsinit(this.data.currectType);
    },
    toEvaluate:function(e){
        wx.navigateTo({
            url: 'to_evaluate?order_no='+e.currentTarget.dataset.id,
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
  onReachBottom: function (e) {
    this.tabsinit(this.data.currectType);
  }
})